package com.example.demo.module.repository.dto;

import com.example.demo.entity.pojo.repository.RepositoryPoJo;
import lombok.Builder;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * tree node.
 *
 * @author Mei Ruoxiao
 * @since 2020/9/14
 */
@Data
@Builder
public class TreeNode {
    protected Long id;
    protected Long parentId;
    protected String name;
    protected List<TreeNode> children = new ArrayList<>();

    public void addNode(TreeNode node) {
        children.add(node);
    }

    public static TreeNode of(final RepositoryPoJo poJo) {
        return TreeNode.builder()
                .id(poJo.getId())
                .parentId(poJo.getParentId())
                .name(poJo.getName())
                .build();
    }
}
